package com.song.demo04springbootweb.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;


//扩展 springmvc 视图解析器
//总结：如果想要div一些定制化的功能，只要写这个组件，然后将它交给springboot,spirngboot会帮我们自动装配
@Configuration
@EnableWebMvc // 委派web MVC配置，从容器中获取所有的webmvcconfig
public class MyMvcConfig implements WebMvcConfigurer {

    //通过扩展spirngmvc，实现强制视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        //实现访问url /hello, 强制跳转到 test.html 测试页面
        registry.addViewController("/hello").setViewName("test");
    }



    //2.注册为bean,被spring接管，可以在 dispatcherservlet 打断点，查看this里面有 myViewResolver 自定义的视图解析器
    //@Bean
    //public ViewResolver myViewResolver(){
    //    return new MyViewResolver();
    //}


    //1.重写 ViewResolver 方法,实现视图解析器接口的类
    //public static class MyViewResolver implements ViewResolver{
    //    @Override
    //    public View resolveViewName(String viewName, Locale locale) throws Exception {
    //        return null;
    //    }
    //}
}
